//table头信息 不变
var um_columnData = [
    {"Width": "8%", "ColumnName": "客户ID"},
    {"Width": "8%", "ColumnName": "客户名称"},
    {"Width": "8%", "ColumnName": "责任人"},
    {"Width": "8%", "ColumnName": "客户类型"},
    {"Width": "8%", "ColumnName": "客户等级"},
    {"Width": "8%", "ColumnName": "联系人"},
    {"Width": "8%", "ColumnName": "手机号"},
    {"Width": "9%", "ColumnName": "身份证"},
    {"Width": "7%", "ColumnName": "来源"},
    {"Width": "8%", "ColumnName": "所属行业"},
    {"Width": "8%", "ColumnName": "录入时间"},
    {"Width": "12%", "ColumnName": "操作"}
];

//操作按钮 不变
var um_operateHtml = "<div class='form-inline'>" +
    "<button type='button' class='btn btn-primary innerButtons' value='modify'>修改 </button> " +
    " <button type='button' class='btn btn-primary innerButtons'  value='unlock'>解锁</button>" +
    " <button type='button' class='btn btn-primary innerButtons'  value='view'>查看</button>" +
    "</div>";


//用户管理分页函数
var gotoPage = function (index) {
    //1.todo url
    var url = webPath + "/crm/1"
    var pageNumber = index;
    var postData = $("#m-customerForm").serialize();
    postData.pageNumber = pageNumber;
    postData.pageSize = pageSize;
    console.log(postData);
    var options = {"passArguments": pageNumber};
    postAjax(url, postData, getCustomerInfoSuccess, options);
};

//TODO 4. toContect = on  待联系人的选中
function getCustomerInfoSuccess(result, passArguments) {
    //2.TODO 数据名改变
    var columnList = ["customerId", "customerName", "responsiblePerson", "customerType", "customerGrade", "contact",
        "phoneNumber", "idNumber", "source", "industry", "recordTime"];
    cleanTableAndPage("clientInfoTable");
    //3.TODO remove
    var result = '{"totalNumber":3,"list":[{"customerId":"33", "customerName":"张三", "customerGrade":"潜在客户",' +
        '"idNumber":"333333333333333333","recordTime":"2015-6-9","contact":"李四",' +
        '"responsiblePerson":"责任人","customerType":"生产企业","source":"网站注册","phoneNumber":"111111111",' +
        '"industry":"钢铁"}]}';
    var jsonData = $.parseJSON(result);
    //画table
    $("#clientInfoTable").MakeTable(false, um_columnData, jsonData.list, tableClass, columnList, um_operateHtml);
    //画分页
    $("#clientInfoTable").after(comPagination(passArguments, pageSize, jsonData.totalNumber, "gotoPage", "clientInfoP"));

    //Table中操作栏 修改 解锁 查看
    $("#clientInfoTable button").click(function () {
        var that = $(this);
        var customerId = getCustomerId(that);
        var buttonType = that.val();
        buttonType === "modify" ?
            getPage(webPath + "/crm/editCustomerInfo/" + customerId + ".do") :
            buttonType === "unlock" ?
                showConfirm("你确定要解锁吗？", function () {
                }) :
                that.val() === "view" ?
                    getPage(webPath + "/crm/getViewRecords/" + customerId + "/0.do") :
                    "";
    });
}

//查询按钮行为
$('#searchBtn').click(function () {
    gotoPage(1);
});

//获取id 方便提交 TODO
var getCustomerId = function (that) {
    return that.closest("tr").find("td div")[1].innerHTML;
}